#ifndef __Nor_Flash_SPI_H
#define __Nor_Flash_SPI_H

#ifdef APM32E10X_HD
	#include "apm32e10x_gpio.h"     
	#include "apm32e10x_rcm.h" 
	#include "apm32e10x_spi.h" 
	
#elif defined AT32F403AVGT7
	#include "at32f403a_407_crm.h"
	#include "at32f403a_407_gpio.h"
	#include "at32f403a_407_spi.h"
		
#else
	#include "apm32f10x_gpio.h"     
	#include "apm32f10x_rcm.h" 
	#include "apm32f10x_spi.h"
#endif

#include "BoardData.h"

//////////////////////// SPI 引脚上拉控制 /////////////////////////
#define  NorFlash_spi_pullup       1       // >0 使能上拉

// Nor Flash SPI 引脚：PB3-PB5 //
#define NorFalsh_SPI_PinRCM                 RCM_APB2_PERIPH_GPIOB                         
#define NorFalsh_SPI_PinPort                GPIOB    
#define NorFalsh_SPI_SCLK_PinId             GPIO_PIN_3                  // SPI通讯引脚
#define NorFalsh_SPI_MOSI_PinId             GPIO_PIN_5  
#define NorFalsh_SPI_MISO_PinId             GPIO_PIN_4  

// 片选引脚 = PA15
#define NorFalsh_SPI_CS_RCM                 RCM_APB2_PERIPH_GPIOA                         
#define NorFalsh_SPI_CS_PinPort             GPIOA    
#define NorFalsh_SPI_CS_PinId               GPIO_PIN_15 

// SPI功能
#define NorFalsh_SPI_RCM                    RCM_APB1_PERIPH_SPI3
#define NorFalsh_SPI_id                     SPI3

// 定义函数
#define NorFalsh_SPI_bit_set(x)             NorFalsh_SPI_PinPort -> BSC = x
#define NorFalsh_SPI_bit_reset(x)           NorFalsh_SPI_PinPort -> BC  = x
#ifdef NorFalsh_SPI_CS_PinPort
#define NorFalsh_SPI_CS_set()              NorFalsh_SPI_CS_PinPort -> BSC = NorFalsh_SPI_CS_PinId
#define NorFalsh_SPI_CS_reset()            NorFalsh_SPI_CS_PinPort -> BC  = NorFalsh_SPI_CS_PinId
#endif

///// 函数声明 //////
void SPI_NorFlash_init(void);
uint8_t SPI_NorFlash_SendRead_Byte(uint8_t data);

#endif


